package com.ws.system.role.service.impl;

import com.ws.system.role.entity.SystemRole;
import com.ws.system.role.mapper.SystemRoleMapper;
import com.ws.system.role.service.ISystemRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.ws.common.utils.PageUtils;

/**
 * <p>
 * 角色 服务实现类
 * </p>
 *
 * @author weifucheng
 * @since 2019-11-11
 */
@Service
public class SystemRoleServiceImpl extends ServiceImpl<SystemRoleMapper, SystemRole> implements ISystemRoleService {

    @Override
    public Page<SystemRole> list(SystemRole systemRole, Integer current, Integer size) {
        Page<SystemRole> page= PageUtils.newPage(current, size);
        page.setRecords(baseMapper.listByParam(page,systemRole));
        return page;
    }

    @Override
    public Set<String> getRolesByUserId(String userId) {
        SystemRole systemRole=new SystemRole();
        systemRole.setUserId(userId);
        List<SystemRole> roles=baseMapper.listUserRoles(systemRole);
        Set<String> rolesSet=new HashSet<String>();
        for (SystemRole role:roles){
            rolesSet.add(role.getRoleCode());
        }
        return rolesSet;
    }

    @Override
    public List<SystemRole> listByUserId(SystemRole systemRole) {
        return baseMapper.listByUserId(systemRole);
    }
}
